package com.hejing.Java比较器;

import org.junit.Test;

import java.util.Arrays;

/**
 * ClassName: ComparableTest
 * Package: com.hejing.Java比较器.Comparable
 * Description:
 *  自然排序
 * @Author: HeJing
 * @Create: 2023-04-17 21:00
 * @Version: 1.0
 */
public class ComparableTest {
    @Test
    public void test01(){
        String[] arr = new String[]{"Tom", "jerry", "Rose", "Tony", "Lucy"};

        Arrays.sort(arr);

        System.out.println("排序后遍历");
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }

    }

    @Test
    public void test02(){
        Product[] arr = new Product[5];
        arr[0] = new Product("HuaweiMate50pro", 8999);
        arr[1] = new Product("xiaomi13pro", 4999);
        arr[2] = new Product("IPhone12Pro", 8999);
        arr[3] = new Product("VivoX90", 5999);
        arr[4] = new Product("OPPOA99", 3999);

        Arrays.sort(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
}





























